package main

import (
	"fmt"
	"sort"
)

func mapkeysort(m map[int]string) {
	keys := make([]int, 0)
	for k := range m {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	for _, k := range keys {
		fmt.Println("keys:", k, "value:", m[k])
	}
}

type Entry struct {
	Key   int
	Value string
}

func mapvaluesort(m map[int]string) {
	// mslice := make([]Entry, 0)
	// for k, v := range m {
	// 	mslice = append(mslice, Entry{Key: k, Value: v})
	// }
	// fmt.Println(mslice)

	p := make([]Entry, len(m))
	i := 0
	for k, v := range m {
		p[i] = Entry{Key: k, Value: v}
		i++
	}
	fmt.Printf("%+v\n", p)
}

func main() {
	m := make(map[int]string)
	m[1] = "ab"
	m[2] = "cd"
	m[3] = "ef"
	m[4] = "gh"
	mapkeysort(m)
	mapvaluesort(m)
}
